package cn.gcxy.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gcxy.entity.Type;
import cn.gcxy.mapper.TypeMapper;
import cn.gcxy.service.TypeService;

@Service(value="typeService")
public class TypeServiceImpl implements TypeService{

	@Autowired	
	@Qualifier(value="typeMapper") 
	TypeMapper typeMapper;
	
	@Override
	public List<Type> queryAllType() {
		return typeMapper.queryAllType();
	}

	@Override
	public List<Type> queryTypeByPid(String pId) {
		return typeMapper.queryTypeByPid(pId);
	}

	@Override
	public String queryPIdById(String bigType) {
		return typeMapper.queryPIdById(bigType);
	}

	@Override
	public boolean editType(Type type) {
		return typeMapper.editType(type);
	}

	@Override
	public boolean deleteType(String id) {
		return typeMapper.deleteType(id);
	}

	@Transactional
	@Override
	public boolean deleteTypeByPid(String id,String pid) {
		boolean flag;
		if("0".equals(pid)) {
			typeMapper.deleteTypeByPid(id);
		}
		flag = typeMapper.deleteType(id);
		return flag;
	}

	@Override
	public String addType(String name, String pid) {
		Type type = new Type(name,pid);
		if(typeMapper.addType(type))
			return type.getId();
		else 
			return "-1";
	}

	@Override
	public List<Type> queryAllBigType() {
		return typeMapper.queryAllBigType();
	}

	@Override
	public Type queryTypeName(String id) {
		Type type = typeMapper.queryTypeById(id);
		return type;
	}
}
